package com.glsc.ngateway.common.base.repo.mysql.opmanage.report.regulatory;

import com.glsc.ngateway.common.base.domain.mysql.opmanage.report.regulatory.RegRptDefine;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.math.BigInteger;
import java.util.List;

/**
 * @author: qiyr
 * @date: 2022/6/30 19:09
 * @description: 监管报送定义数据访问层
 */
@Repository
public interface RegRptDefineRepo extends JpaRepository<RegRptDefine, BigInteger>, JpaSpecificationExecutor<RegRptDefine> {

    @Query(value = "select trrd.* from glsc_data.t_reg_rpt_define trrd join glsc_data.t_import_match tim on " +
            "tim.fl_importid = trrd.import_config_id where tim.fc_catid = :catid", nativeQuery = true)
    List<RegRptDefine> findByCatId(@Param("catid") String catId);

    @Query(value = "select trrd.* from glsc_data.t_reg_rpt_define trrd inner join " +
            "glsc_data.t_import_match tim on tim.fl_importid = trrd.import_config_id", nativeQuery = true)
    List<RegRptDefine> findAllExist();

    @Query(value = "select" +
            "           td.*" +
            "       from" +
            "           glsc_data.t_reg_rpt_main tm" +
            "       inner join" +
            "           glsc_data.t_reg_rpt_define td" +
            "           on tm.rpt_define_id = td.id" +
            "       where" +
            "           tm.status = 0" +
            "           and tm.bizdate = :bizdate" +
            "           and td.import_config_id in (:importIdList)" +
            "           and tm.dimension1 = '国联证券'" +
            "       order by" +
            "           td.id", nativeQuery = true)
    List<RegRptDefine> findMergedList(@Param("importIdList") List<BigInteger> importIdList, @Param("bizdate") String bizdate);

}
